﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using COM.OA.Entity;
using COM.OA.BLL;
using System.Collections.Generic;

public partial class gxxz_zhuanfa : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ddl_bumen_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ddl_bumen.Text !="选择部门")
        {
            int id = Int32.Parse(this.ddl_bumen.Text);
            SqlParameter bumen = new SqlParameter("@dept_id", id);
            IList<lbEmploy> list = BLLGeneric.Select<lbEmploy>(CommandType.StoredProcedure, "lb_liandong", bumen);
            //配置数据源
            this.ddl_em.DataSource = list;
            //绑定字段属性
            this.ddl_em.DataTextField = "Em_name";
            this.ddl_em.DataValueField = "Em_name";
            //绑定控件
            this.ddl_em.DataBind();
        }
        else
        {
            this.Response.Write(string.Format(GetRedirect.WINALERT, "请选择部门"));
            this.ddl_bumen.Focus();
            return;
        }
        
    }
    protected void btnfs_Click(object sender, EventArgs e)
    {
        this.check();
    }
    //验证成功后向数据库插入数据
    protected void check()
    {

        if (this.ddl_bumen.Text == "选择部门")
        {
            this.Response.Write(string.Format(GetRedirect.WINALERT, "请选择部门"));
            this.ddl_bumen.Focus();
            return;
        }
        else
        {
            if (this.ddl_em.Text == "选择对象")
            {
                this.Response.Write(string.Format(GetRedirect.WINALERT, "请选择对象"));
                this.ddl_em.Focus();
                return;
            }
            else
            {
                files f = (files)Session["bfile"];
                //设置文件的实体
                files file = new files();

                //部门ID

                file.f_dept_id = Int32.Parse(this.ddl_bumen.Text);
                //文件名
                file.f_filename = f.f_filename;
                //文件类型
                file.f_ftype_id = f.f_ftype_id;
                //读否
                file.f_isread = 0;
                //是否回执
                file.f_isreturn = 0;
                //是否共享
                file.f_isshare = 0;
                //阅读次数
                file.f_readdegree = 0;
                //转发时间
                file.f_releasetime = DateTime.Now.ToLocalTime();
                //文件状态
                file.f_state = 0;
                //发送人
                file.f_sendu_id = f.f_sendu_id;
                //接收人
                string where = "em_name ='" + this.ddl_em.Text+"'";
                IList<employee> elist = employeeBLL.Select(where);
                employee emp = elist[0];

                IList<users> uList = usersBLL.Select("u_em_id="+emp.em_id);
                users u = uList[0];
                file.f_takeu_id = u.u_id;
; 
                //附言
                
                file.f_remark ="附言";
               
                COM.OA.BLL.filesBLL.Insert(file);
                Session.Add("filepost", file);
                this.Response.Redirect("scsecce.aspx");
            }
        }
    }
}
